﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Configuration;

namespace CrawlServiceCore.Configuration
{
    public class CrawlDetailsElementCollection:ConfigurationElementCollection
    {
        #region Constructor
        public CrawlDetailsElementCollection()
        { }
        #endregion

        #region Properties
        public int CollectionCount
        {
            get { return base.Count; }
        }
        #endregion

        #region Configuration Attributes / Properties

        #endregion

        #region Overrides
        protected override ConfigurationElement CreateNewElement()
        {
            return new CrawlSiteElementCollection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((CrawlSiteElementCollection)element).SiteName;
        }
        #endregion

        #region Children Management
        public CrawlSiteElementCollection this[int index]
        {
            get { return (CrawlSiteElementCollection)BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                    BaseRemoveAt(index);

                BaseAdd(index, value);
            }
        }

        new public CrawlSiteElementCollection this[string SiteName]
        {
            get { return (CrawlSiteElementCollection)BaseGet(SiteName); }
        }

        public int IndexOf(CrawlSiteElementCollection element)
        {
            return BaseIndexOf(element);
        }

        public void Add(CrawlSiteElementCollection element)
        {
            BaseAdd(element);
        }
        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
        }

        public void Remove(CrawlSiteElementCollection element)
        {
            if (BaseIndexOf(element) >= 0)
                BaseRemove(element.SiteName);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string SiteName)
        {
            BaseRemove(SiteName);
        }

        public void Clear()
        {
            BaseClear();
        }
        #endregion
    }
}
